package main.java;
import org.junit.Test;

import java.util.*;

public class TreeSetTest {
    @Test
    public void test1(){
        TreeMap<Integer,Integer> treeMap = new TreeMap<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        treeMap.put(1,3);
        Integer a = treeMap.get(1);
        System.out.println(a);
        treeMap.put(2,4);
        System.out.println("完整的treemap:"+ treeMap.toString());
        Set<Integer> set =  treeMap.keySet();
        Collection<Integer> list = treeMap.values();
        for (Integer i:set
             ) {
            System.out.println(i+"  "+treeMap.get(i));
        }
        for (Integer i:list
             ) {
            System.out.println(i);
        }

    }
    @Test
    public void test2(){
        LinkedList<Integer> linkedList =new LinkedList<>();
        linkedList.add(1);
        linkedList.add(2);
        linkedList.add(3);
        Collections.sort(linkedList, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        System.out.println(linkedList.toString());
    }
    @Test
    public void test3(){
        Map<Size,Integer> map =new EnumMap<Size, Integer>(Size.class);
    }
    int a=3;
    int b =3;

    //打印内存地址
    @Test
    public void test4() throws Exception {

        System.out.println(System.identityHashCode(a));
        System.out.println(System.identityHashCode(b));
        a=4;
        System.out.println(System.identityHashCode(a));
        System.out.println(System.identityHashCode(b));
        b=4;
        System.out.println(System.identityHashCode(b));
        b=3;
        System.out.println(System.identityHashCode(b));
    }

    public enum Size{
        SMALL,MEDIEM,LARGE
    }

}
